#ifndef RPC_ACCEPTOR_H_
#define RPC_ACCEPTOR_H_

#include "base/base.h"

namespace rpc {
struct Event;
class Socket;
class Protocol;
class RpcServer;
class EventManager;

class Acceptor {
  public:
    Acceptor(RpcServer* owner, EventManager* ev_mgr);
    ~Acceptor();

    void SetProtocol(Protocol* h) {
      CHECK_NOTNULL(h);
      protocol_ = h;
    }

    // must set protocol first.
    bool Init(const std::string& ip, uint16 port);

    void HandleEvent();

  private:
    RpcServer* owner_;
    EventManager* ev_mgr_;

    scoped_ptr<Event> accept_event_;
    scoped_ptr<Socket> accept_socket_;

    Protocol* protocol_;

    DISALLOW_COPY_AND_ASSIGN(Acceptor);
};
}

#endif
